package com.ruoyi.open.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.constants.IndustrialConstants;
import com.ruoyi.dataBase.domain.bo.IndustrialTransportProjectBo;
import com.ruoyi.dataBase.domain.vo.IndustrialTransportProjectVo;
import com.ruoyi.dataBase.service.IIndustrialTransportProjectService;
import com.ruoyi.reportInfo.domain.bo.IndustrialParkBo;
import com.ruoyi.reportInfo.domain.vo.IndustrialParkVo;
import com.ruoyi.reportInfo.service.IIndustrialParkService;
import com.ruoyi.reportReview.domain.bo.IndustrialReportInfoBo;
import com.ruoyi.reportReview.domain.bo.IndustrialReportTotalInfoBo;
import com.ruoyi.reportReview.service.IIndustrialReportInfoService;
import com.ruoyi.reportTask.domain.vo.IndustrialReportTaskCenterVo;
import com.ruoyi.reportTask.service.IIndustrialReportTaskCenterService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 产业地图开放接口
 */
@Validated
@SaIgnore
@RequiredArgsConstructor
@RestController
@RequestMapping("/industrial/open")
public class IndustrialOpenController extends BaseController {

    private final IIndustrialTransportProjectService iIndustrialTransportProjectService;

    private final IIndustrialReportTaskCenterService iIndustrialReportTaskCenterService;

    private final IIndustrialReportInfoService iIndustrialReportInfoService;

    private final IIndustrialParkService iIndustrialParkService;

    /**
     * 查询交通物流项目列表
     */
    @GetMapping("/transportProject/list")
    public TableDataInfo<IndustrialTransportProjectVo> list(IndustrialTransportProjectBo bo, PageQuery pageQuery) {
        TableDataInfo<IndustrialTransportProjectVo> industrialTransportProjectVoTableDataInfo = iIndustrialTransportProjectService.queryPageList(bo, pageQuery);
        if (CollectionUtils.isNotEmpty(industrialTransportProjectVoTableDataInfo.getRows())){
            industrialTransportProjectVoTableDataInfo.getRows().forEach(industrialTransportProjectVo -> industrialTransportProjectVo.setBuildStatusStr(IndustrialConstants.buildStatusMap.get(industrialTransportProjectVo.getBuildStatus())));
        }
        return industrialTransportProjectVoTableDataInfo;
    }


    /**
     * 查询园区信息列表
     */
    @GetMapping("/listTransportPark/list")
    @Operation(summary = "查询园区信息列表", description = "用于查询园区信息列表")
    public TableDataInfo<IndustrialParkVo> list(IndustrialParkBo bo, PageQuery pageQuery) {
        return iIndustrialParkService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取填报任务中心详细信息
     *
     * @param id 主键
     */
    @GetMapping("/reportTaskCenter/{id}")
    public R<IndustrialReportTaskCenterVo> getInfo(@NotNull(message = "主键不能为空")
                                                   @PathVariable String id) {
        return R.ok(iIndustrialReportTaskCenterService.queryById(id));
    }


    /**
     * 新增填报
     * @return
     */
    @RepeatSubmit()
    @PostMapping("/addReportInfo")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody IndustrialReportTotalInfoBo industrialReportTotalInfoBo) throws IllegalAccessException {
        return toAjax(iIndustrialReportInfoService.insertReportTotalInfo(industrialReportTotalInfoBo));
    }

}
